/*
 * Copyright (C) 2018 Logos Technology Ltd.
 */

package com.logos.tool.map;

/**
 * @author guoyalong
 *         矩形工具类
 */
public class RectangleUtil {

    /**
     * 判断两个矩形是否有公共部分
     *
     * @param rect  矩形1
     * @param rect1 矩形2
     * @return 有公共部分true，没有false
     */
    public static boolean isRectCommonPart(Rectangle rect, Rectangle rect1) {
        Point point = new Point();
        point.setX(((rect.right + rect.left) / 2 + (rect1.right + rect1.left) / 2) / 2);
        point.setY(((rect.top + rect.bottom) / 2 + (rect1.top + rect1.bottom) / 2) / 2);
        return isPointInsideRect(point, rect) && isPointInsideRect(point, rect1);
    }

    /**
     * 判断点是不是在矩形内部,不包括在线的边上
     *
     * @param point 点
     * @param rect  矩形
     * @return true在矩形内部，false不在矩形内部
     */
    private static boolean isPointInsideRect(Point point, Rectangle rect) {
        return point.getX() > rect.left && point.getX() < rect.right
                && point.getY() > rect.top && point.getY() < rect.bottom;
    }
}
